import 'package:catsao/mock/video.dart';
import 'package:catsao/util/event_bus.dart';
import 'package:catsao/views/VideoThumbnail.dart';
import 'package:flutter/material.dart';

// List imgList = [
//   {"url": "images/1.jpg"},
//   {"url": "images/2.jpg"},
//   {"url": "images/3.jpg"},
//   {"url": "images/4.jpg"},
//   {"url": "images/2.jpg"},
//   {"url": "images/3.jpg"},
//   {"url": "images/4.jpg"},
//   {"url": "images/5.jpg"},
//   {"url": "images/6.jpg"}
// ];

class InfiniteListView extends StatefulWidget {
  InfiniteListView({Key key, this.tabName, this.videoid}) : super(key: key);
  String tabName;
  final int videoid;

  @override
  _InfiniteListView createState() => new _InfiniteListView();
}

class _InfiniteListView extends State<InfiniteListView> {
  ScrollController _scrollController = new ScrollController();
  List<UserVideo> videoDataList = [];

  // Future<dynamic> _onLoadmore() {
  //   var data = {"url": "images/3.jpg"};
  //   this.setState(() {
  //     imgList.add(data);
  //   });
  // }

  @override
  void dispose() {
    //为了避免内存泄露，需要调用_controller.dispose
    _scrollController.dispose();
    super.dispose();
  }

  void initState() {
    videoDataList = UserVideo.fetchVideo();
    super.initState();

    // _scrollController.addListener(() {
    //   if (_scrollController.position.pixels ==
    //       _scrollController.position.maxScrollExtent) {
    //     _onLoadmore();
    //   }
    // });
  }

  // Widget _loadMoreWidget() {
  //   return new Padding(
  //     padding: const EdgeInsets.all(15.0),
  //     child: new Center(child: new CircularProgressIndicator()),
  //   );
  // }

  @override
  Widget build(BuildContext context) {
    return new Card(
      child: new Material(
        child: Container(
            margin: new EdgeInsets.symmetric(vertical: 2.0),
            child: Column(
              children: <Widget>[
                Container(
                  height: 200.0,
                  child: new ListView.builder(
                      controller: _scrollController,
                      scrollDirection: Axis.horizontal,
                      itemCount: videoDataList.length,
                      itemBuilder: (BuildContext context, int index) {
                        // if (index == videoDataList.length - 1) {
                        //   return _loadMoreWidget();
                        // }

                        // else {
                        return Container(
                            child: Row(
                              children: <Widget>[
                                SizedBox(
                                  width: 150,
                                  height: double.infinity,
                                  child: Stack(
                                    fit: StackFit.expand,
                                    children: <Widget>[
                                      // Image(
                                      //   image: AssetImage(
                                      //     videoDataList[index],
                                      //   ),
                                      //   fit: BoxFit.fill,
                                      // ),
                                      VideoThumbnail(
                                        videourl: videoDataList[index].url,
                                        aspectRatiowidth: 3.8,
                                        aspectRatioheight: 5,
                                      ),
                                      Material(
                                          color: Colors.transparent,
                                          child: IconButton(
                                            splashColor: Colors.transparent,
                                            highlightColor: Colors.transparent,
                                            icon:
                                            Icon(Icons.play_circle_fill_sharp),
                                            color: Color(0X66e5e0e0),
                                            iconSize: 50,
                                            onPressed: () => eventBus.fire(
                                                new EventBusVideoControll(
                                                    index.toString())),
                                          ))
                                    ],
                                  ),
                                ),
                              ],
                            ));
                        // }
                      }),
                ),
              ],
            )),
      ),
    );
  }
}
